package com.xwaiy.xwaiyrpc.serializer;

//import com.sun.xml.internal.txw2.output.XmlSerializer;
import com.xwaiy.xwaiyrpc.spi.SpiLoader;

import java.util.HashMap;
import java.util.Map;

/**
 * 序列化器工厂
 * @Author Xwaiy
 * @Date 2025/8/25 16:24
 **/
public class SerializerFactory {

    static {
        SpiLoader.load(Serializer.class);
    }

    // 默认序列化器
    private static final Serializer DEF_SERIALIZER = new JdkSerializer();

    public static Serializer getInstance(String key) {
        return SpiLoader.getInstance(Serializer.class,key);
    }

    //  硬编码 HashMap  begin
//    private static final Map<String, Serializer> SERIALIZERS_MAP = new HashMap<String, Serializer>() {{
//        put(SerializerKeys.JDK, new JdkSerializer());
//        put(SerializerKeys.JSON, new JsonSerializer());
//        put(SerializerKeys.KRYO, new KryoSerializer());
//        put(SerializerKeys.HESSIAN, new HessianSerializer());
//    }};
//
//    /**
//     * 默认序列化器
//     */
//    private static final Serializer DEF_SERIALIZER = SERIALIZERS_MAP.get(SerializerKeys.JDK);
//
//    public static Serializer getInstance(String key) {
//        return SERIALIZERS_MAP.getOrDefault(key, DEF_SERIALIZER);
//    }
    // end
}
